package presentation;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import controleur.Transactions;

public class FenetreVente extends JFrame implements ActionListener {

	private JButton btVente;
	private JTextField txtQuantite;
	private JComboBox combo;
	private Transactions ts;

	public FenetreVente(Transactions s) {

		ts = s;
		setTitle("Vente");
		setBounds(500, 500, 200, 125);
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());
		btVente = new JButton("Vente");
		txtQuantite = new JTextField(5);
		txtQuantite.setText("0");

		combo = new JComboBox(ts.listeProduits());
		combo.setPreferredSize(new Dimension(100, 20));
		contentPane.add(new JLabel("Produit"));
		contentPane.add(combo);
		contentPane.add(new JLabel("Quantit� vendue"));
		contentPane.add(txtQuantite);
		contentPane.add(btVente);

		btVente.addActionListener(this);

		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource () == btVente) {
		ts.vendre((String)combo.getSelectedItem(),
				Integer.valueOf(txtQuantite.getText()));
		this.dispose();
		}
	}
}
